
package com.rx.mgt.util;  

import javax.servlet.http.HttpServletRequest;

import com.rx.mgt.domain.AdminUser;

/** 
 * ClassName:IpUtil 
 * Function :
 * Reason   : 
 * Date     :Feb 6, 2017 3:37:03 PM 
 * @author   luolei 
 * @since    JDK 1.6
 */
public class IpUtil {
    /**
     * 从request对象中获取客户端真实的ip地址
     * @param request request对象
     * @return 客户端的IP地址
     */
    public static String getIpAddr(HttpServletRequest request) {
//        AdminUser user = (AdminUser) request.getSession().getAttribute("user");
//        sysLogService.add("", IpUtil.getIpAddr(request), "管理", user.getId()+"", user.getUser_name());
        String ip = request.getHeader("x-forwarded-for");
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknow".equalsIgnoreCase(ip)) {
            ip = request.getHeader("WL-Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getRemoteAddr();
        }
        return ip;
    }
}
  